﻿
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using ZXing.QrCode;

namespace 盎宇宙服务
{
    public class QRCodeUtil
    {
        /// <summary>
        /// 解码二维码,返回一个文本字符串，如果返回为null，则解析(转化)失败
        /// </summary>
        /// <param name="barcodeBitmap">待解码的二维码图片</param>
        /// <returns>扫码结果</returns>
        public static string DecodeQrCode(Bitmap barcodeBitmap)
        {
            BarcodeReader reader = new BarcodeReader();
            reader.Options.CharacterSet = "UTF-8";
            Result result = reader.Decode(barcodeBitmap);
            return (result == null) ? null : result.Text;
        }

        public static Bitmap GetBitmap(string path)
        {
            Bitmap bitmap = new Bitmap(path);

            return bitmap;
        }
        public static string DecodeQrCodeByPath(string path)
        {
            return DecodeQrCode(GetBitmap(path));
        }
    }
}
